﻿using System;
using Phoenix.ActionResults;

namespace Phoenix.Filters.ResultFilters
{
    public class TargetFrameResultFilter : IResultFilter
    {
        public void OnResultExecuting(ResultExecutingContext filterContext)
        {
            if (!(filterContext.Result is ViewActionResult))return;
            if (filterContext.PreviousContext == null) return;
            if (filterContext.PreviousContext.ContentFrame == null) return;
            if (filterContext.CurrentContext.NavigationFrame == filterContext.CurrentContext.ContentFrame) return;

            var controllerActionContext = filterContext.PreviousContext;
            var contentFrame = controllerActionContext.ContentFrame;
            contentFrame.RegisterChild(filterContext.CurrentContext.ContentFrame);
        }

        public void OnResultExecuted(ResultExecutedContext filterContext)
        {
            
        }
    }
}